package StudyCode.summary.myfile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ReadingPropertyFiles {
	public static void main(String[] args) throws Exception {
		File file = new File("properties.conf");
		Properties properties = null;
		if (!file.exists()) {
			file.createNewFile();
		}
		properties = new Properties();
		properties.load(new FileInputStream("properties.conf"));
		boolean shouldWakeUp = false;
		int startCounter = 100;
		String shouldWakeUpProperty = properties.getProperty("ShouldWakeup");
		shouldWakeUp = (shouldWakeUpProperty == null) ? false : Boolean.parseBoolean(shouldWakeUpProperty.trim());

		String startCounterProperty = properties.getProperty("StartCounter") == null ? "0" : properties.getProperty("StartCounter");
		startCounter = Integer.parseInt(startCounterProperty);
		String dateFormatStringProperty = properties.getProperty("DateFormatString", "MMM dd yy");

		System.out.println("Should Wake up? " + shouldWakeUp);
		System.out.println("Start Counter: " + startCounter);
		System.out.println("Date Format String:" + dateFormatStringProperty);

		properties.setProperty("StartCounter", "250");
		properties.store(new FileOutputStream("properties.conf"), "Properties Description");
		properties.list(System.out);
	}
}
